package cloud.dandanit.itservice.controller.view;


import cloud.dandanit.itservice.entity.View;
import cloud.dandanit.itservice.service.ViewService;
import cloud.dandanit.itservice.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author luokai
 * @since 2022-07-03
 */
@RestController
@RequestMapping("/itservice/view")
public class ViewController {

    @Autowired
    private ViewService viewService;

    /**
     * 获取浏览数
     * @return 浏览数
     */
    @GetMapping("getViewNum")
    public R getViewNum() {

        Integer viewNum = viewService.getViewNum();
        return R.ok().data("viewNum",viewNum);
    }

    /**
     * 增加浏览数存redis)
     * @param viewNum 浏览数
     * @return 成功
     */
    @GetMapping("addViewNum/{viewNum}")
    public R addViewNum(@PathVariable String viewNum) {

        viewService.addViewNumToRedis(viewNum);
        return R.ok();
    }
}

